<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查询用户分享的美食</title>
    <!-- 移动设备优先 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- BS4依赖 -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jquery-3.4.0.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/vue.js"></script>
    <!-- json依赖 -->
    <script src="js/json2.js"></script>
    <style type="text/css">
        /* 三层div用于按比例缩放图片 */
        .demo {
            width: 100%;
            height: 400px;
            overflow: hidden;
        }
        .demo1-1 {
            float: left;
            width: 280px;
            height: 280px;
        }
        .zoomImage {
            width: 100%;
            height: 0;
            padding-top: 100%;
            overflow: hidden;
            background-position: center center;
            background-repeat: no-repeat;
            background-size: cover;
            -webkit-background-size: cover;
            -moz-background-size: cover;
        }

        /* div阴影显示 */
        .show-shadow:hover{
            -webkit-box-shadow: #666 0px 0px 10px;
            -moz-box-shadow: #666 0px 0px 10px;
            box-shadow: #666 0px 0px 10px;
        }

        /* Make the image fully responsive */
        .carousel-inner img {
            width: 100%;
            height: 100%;
        }
    </style>
    <script>
    </script>

    <script>
        // 全局变量用来保存美食ID（用于删除或者获取详细信息）
        var cateId = 0;
        // 获取美食信息
        $.ajax({
            // 请求地址、请求方式、预期返回数据类型、成功回调函数
            url: "selectCate", type: "post", dataType: "json", data: {"cateId": ""},
            success: function (list) {
                var object = list;
                // append在内部添加元素
                for (var row in object) {
                    $("#show").append(
                        "<div class=\"col-md-3 bg-light\">" +
                        "<div class=\"card\" style=\"width: 18rem;\">" +
                        "<div class='demo1-1'><div class='zoomImage d-block w-100 rounded' style=\"background-image: url(" + object[row].cateImage + ")\"></div></div>" +
                        "<div class=\"card-body\">" +
                        "<h5 class=\"card-title\">" + object[row].cateName + "</h5>" +
                        "<p id=\"history1\" class=\"card-text\"  style=\"font-size: 12px; line-height: 2;\" >" + object[row].userName + "</p>" +
                        "<a href=\"editCateInfo.html?cate_id=" + object[row].cateId + "\" target=\"userInfo\" class=\"btn btn-info\">编辑美食</a>" +
                        "<a href=\"javascript:void(0)\" target=\"userInfo\" class=\"btn btn-danger\" onclick=\"showModel(" + object[row].cateId + ")\">删除美食</a>" +
                        "</div></div></div>"
                    );
                }
            },
            // data-toggle="modal" data-target="#exampleModal"
            // 失败回调函数
            error: function () {
                alert("系统出错!! 请重新登录！！");
                window.parent.location.href = "/main.html";
            }
        });

        // 显示模态框并为美食id赋值
        function showModel(id) {
            cateId = id;
            $('#tipModal').modal('show');
        }

        // 执行删除美食操作
        $(function () {
            $("#delButton").click(function () {
                $.ajax({
                    url: "delCate",
                    type: "post",
                    data: {"cateId" : cateId},
                    success: function (data) {
                        if (data == "ok") {
                            alert("删除成功！");
                            window.parent.location.href = "center.html";
                        } else {
                            alert("删除失败！");
                        }
                    },
                    error: function () {
                        alert("系统出错，请稍后再试！");
                    }
                })
            });
        });

    </script>
    <style>
        .row {
            margin-right: -5px;
            margin-left: -5px;
        }
        .col-md-3 {
            position: relative;
            min-height: 1px;
            padding-right: 0px;
            padding-left: 0px;
        }
    </style>
</head>
<body class="bg-light">
    <div class="container-fluid" id="app">
        <div class="row" id="show">
        </div>
    </div>
    <!-- 删除美食分享提示框 -->
    <div class="modal fade" id="tipModal">
        <div class="modal-dialog">
            <div class="modal-content">
                    <!-- 模态框头部 -->
                    <div class="modal-header">
                        <h4 class="modal-title">Tips</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <!-- 模态框主体 -->
                    <div class="modal-body">
                        <p>您确定删除该分享吗？</p>
                    </div>
                    <!-- 模态框底部 -->
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                        <button id="delButton" type="button" class="btn btn-primary" data-dismiss="modal">确认删除</button>
                    </div>
            </div>
        </div>
    </div>
</body>
</html>